package com.cat.monotonicStack;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/online-stock-span/description/
 * @create 2025/8/12 20:54
 * @since JDK17
 */

public class StockSpanner {
    static int N = ((int) (1e4 + 10)), top, idx;
    static int[][] stack = new int[N][2];

    public StockSpanner() {
        idx = top = stack[0][1] = 0;
        stack[0][0] = Integer.MAX_VALUE;
    }

    public int next(int price) {
        idx++;
        while (top > 0 && stack[top][0] <= price) {
            top--;
        }
        int res = idx - stack[top][1];
        stack[++top][0] = price;
        stack[top][1] = idx;
        return res;
    }
}